/*
给你一个字符串 s ，其中包含字母顺序打乱的用英文单词表示的若干数字（0-9）。按 升序 返回原始的数字。

 

示例 1：

输入：s = "owoztneoer"
输出："012"
示例 2：

输入：s = "fviefuro"
输出："45"
 

提示：

1 <= s.length <= 105
s[i] 为 ["e","g","f","i","h","o","n","s","r","u","t","w","v","x","z"] 这些字符之一
s 保证是一个符合题目要求的字符串

来源：力扣（LeetCode）
链接：https://leetcode-cn.com/problems/reconstruct-original-digits-from-english
著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。
*/

#include "../stdc++.h"

/*
zero
one
two
three
four
five
six
seven
eight
nine
ten
*/
class Solution {
public:
    string originalDigits(string s) {
        unordered_map<char, int> dict; // 统计每个字母出现的次数
        for (char& c : s) {
            ++dict[c];
        }
        vector<int> count(10, 0); // // 每个数字出现的次数
        count[0] = dict['z'];
        count[2] = dict['w'];
        count[4] = dict['u'];
        count[6] = dict['x'];
        count[8] = dict['g'];
        count[3] = dict['h'] - count[8];
        count[5] = dict['f'] - count[4];
        count[7] = dict['s'] - count[6];
        count[1] = dict['o'] - count[0] - count[2] - count[4];
        count[9] = dict['i'] - count[5] - count[6] - count[8];
        string res;
        for (int i{0}; i < 10; ++i) {
            res += string(count[i], i + '0');
        }
        return res;
    }
};
